package com.lz.dsp.task.config.kafka;

import com.lz.common.util.GetCfg;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;


/**
 * kafka消费者配置属性
 */
@Data
@Component
@ConfigurationProperties(prefix = "kafka.consumer.connectinfo")
@DependsOn("init")
@Slf4j
public class KafkaConsumerConnectionInfo {
    private String bootstrapServers="192.168.10.9:9092,192.168.10.10:9092";
    private int fetchMaxWaitMs=500;
    private int fetchMinBytes=1;
    private int fetchMaxBytes=52428800;
    private int maxPollRecords=1;
    private String clientId="lzmh-dsp-task";
    private String autoOffsetReset="latest";
    private String partitionAssignmentStrategy;
    private String interceptorClasses;

    @PostConstruct
    private void init() {
        bootstrapServers= GetCfg.getDefaultValue("kafka.consumer.connectinfo.bootstrapServers", bootstrapServers);
        fetchMaxWaitMs=Integer.parseInt(GetCfg.getDefaultValue("kafka.consumer.connectinfo.fetchMaxWaitMs", String.valueOf(fetchMaxWaitMs)));
        fetchMinBytes=Integer.parseInt(GetCfg.getDefaultValue("kafka.consumer.connectinfo.fetchMinBytes", String.valueOf(fetchMinBytes)));
        fetchMaxBytes=Integer.parseInt(GetCfg.getDefaultValue("kafka.consumer.connectinfo.fetchMaxBytes", String.valueOf(fetchMaxBytes)));
        maxPollRecords=Integer.parseInt(GetCfg.getDefaultValue("kafka.consumer.connectinfo.maxPollRecords", String.valueOf(maxPollRecords)));
        // 打印参数
        log.info("\nkafka consumer config: \n" +
                        "bootstrap.servers = {} \n" +
                        "fetch.max.wait.ms = {} \n" +
                        "fetch.min.bytes = {} \n" +
                        "fetch.max.bytes = {} \n" +
                        "max.poll.records = {} \n" +
                        "client.id = {} \n" +
                        "auto.offset.reset = {} \n" +
                        "partition.assignment.strategy = {} \n" +
                        "interceptor.classes = {} \n",
                bootstrapServers,fetchMaxWaitMs,fetchMinBytes,fetchMaxBytes,maxPollRecords,
                clientId,autoOffsetReset,partitionAssignmentStrategy,interceptorClasses);
    }
}
